-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday12 - part1.py
More file actions
43 lines (36 loc) · 920 Bytes
/
Copy pathday12 - part1.py
File metadata and controls
43 lines (36 loc) · 920 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from enum import Enum
file = open("input.txt")
lines = file.readlines()
class Directon(Enum):
EAST = 0
SOUTH = 90
WEST = 180
NORTH = 270
hor = 0
ver = 0
ori = Directon.EAST.value
for line in lines:
action, val = line[0], int(line[1:])
if action == "N":
ver += val
if action == "S":
ver -= val
if action == "E":
hor += val
if action == "W":
hor -= val
if action == "R":
ori = (ori + val) % 360
if action == "L":
ori = (ori - val) % 360
if action == "F":
if ori == Directon.NORTH.value:
ver += val
if ori == Directon.SOUTH.value:
ver -= val
if ori == Directon.EAST.value:
hor += val
if ori == Directon.WEST.value:
hor -= val
# print(line[:-1], "\t", hor, ver, ori)
print(abs(ver) + abs(hor))